package com.opesoft.fw.mvc.taglib;

import javax.servlet.jsp.JspException;

public class Option extends FormBase
{
	protected String value;
	protected String other;

	protected Select select;

	public int doStartTag() throws JspException
	{
		if(this.getParent()==null||!(this.getParent() instanceof Select)) throw new JspException("Option tag must have a parent tag as Select .");

		this.select=(Select)this.getParent();

		return super.doStartTag();
	}

	public int doEndTag() throws JspException
	{
		String html="<option";
		if(this.value!=null)
		{
			html+=this.htmlProprty("value",this.value);
			if(this.value.equals(select.value)) html+=" selected";
		}
		if(this.other!=null) html+=" "+other;
		html+="/>";

		this.write(html);
		this.select=null;

		return super.doEndTag();
	}

	public String getOther()
	{
		return other;
	}

	public void setOther(String other)
	{
		this.other=other;
	}

	public String getValue()
	{
		return value;
	}

	public void setValue(String value)
	{
		this.value=value;
	}

}
